<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('order_edit_status_page_title'));

$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css')
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.datepicker.css')
    ;

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.datepicker.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/tomato/util.js');
    ;
?>
<style>
    .prefix_1 .t_a_bottom span{
        height:26px;
        line-height:26px;
        text-align:right;
        width:140px;
    }
    .prefix_1 .t_a_bottom label {
        display:block;
        float:left;
        height:26px;
        margin-right:0px;
        text-align:left;
        line-height:26px;
    }
    label.error {
        left:310px;
        position:inherit;
    }
</style>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'order_order_list'); ?>"><?php echo $this->translator('order_list_breadcump'); ?></a></span>
    <span><a href="<?php echo $this->url(array('order_id' => $this->order->order_id), 'order_order_view'); ?>"><?php echo $this->translator('order_view_breadcump'); ?></a></span>
    <span><?php echo $this->translator('order_edit_status_breadcump'); ?></span>
</div>

<?php if(!$this->isAllowed):?>
<div class="grid_12 t_a_bottom"><?php echo $this->translator('order_tracking_permission_guide');?></div>
<?php else:?>
<div class="grid_12 t_a_bottom">
    <a href="<?php echo $this->url(array('order_id' => $this->order->order_id), 'order_order_view'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('order_edit_btn_back'); ?></span></a>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>
<?php
    /**
    * Order info
    **/
    $order = $this->order;

    /**
     * Current user
     **/
    $user = $this->user;
?>
<form method="post" action="" id="editTrackingForm">
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('order_id'); ?>:</label>
                <span><?php echo ($order->order_invoice)?$order->order_invoice:'-';?></span>
            </div>
            <div class="grid_5 omega">
                <label><?php echo $this->translator('order_actual_tracking_status'); ?>:</label>
                <span><?php echo (trim($this->status))?$this->translator('order_tracking_status_'.$this->status):'-';?></span>
            </div>
        </div>
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('order_new_tracking_date'); ?>:</label>
                <input value="<?php echo date('d/m/Y');?>" type="text" name="order_tracking_date" id="order_tracking_date" style="width: 100px"/>
            </div>
        </div>
        <div class="clearfix t_a_bottom">
            <div class="grid_10 alpha" style="width: 900px;">
                <div class="grid_4 alpha">
                    <label><?php echo $this->translator('order_new_tracking_status'); ?>:</label>
                    <select style="width:120px;" name="process_id" >
                        <option value="">--<?php echo $this->translator('order_tracking_step_choose')?>--</option>
                        <?php foreach($this->arrSteps as $key=>$step):?>
                        <?php if(strstr($step->performer_role_id_chain,','.$user->role_id.',')):?>
                        <option value="<?php echo $this->arrProcess[$key];?>"><?php echo $this->translator('order_tracking_step_'.$step->code);?></option>
                        <?php endif;?>
                        <?php endforeach;?>
                    </select>
                </div>
                <div class="grid_6 alpha" style="width: 550px;">
                	<div style="float: left;">
                    <label style="width: auto; height: auto; margin-right: 5px;"><?php echo $this->translator('order_tracking_remark'); ?>:</label>
                    <textarea name="order_tracking_remark" rows="4" style="width: 300px;"></textarea> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                    <div style="float: left;">
                    <label style="width: auto; height: auto; margin-right: 5px;"><?php echo $this->translator('order_tracking_cost'); ?>:</label>
                    <input type="text" name="order_tracking_cost" class="number" style="width:100px;">
                    </div>
                </div>
            </div>
        </div>
        <?php if(strstr($this->strRoleId, ','.$this->user->role_id.',')):?>
        <div class="clearfix t_a_bottom">
            <div class="grid_10 alpha">
                <label>&nbsp;</label>
                <button type="submit"><span style="height:30px; text-align:center; width:auto;" ><?php echo $this->translator('tracking_save_button');?></span></button>
            </div>
        </div>
        <?php endif;?>
    </div>
</div>
</form>

<div class="grid_12 t_a_ui_data_list_header">
    <div class="grid_4 alpha"><?php echo $this->translator('order_edit_tracking_status'); ?></div>
    <div class="grid_3"><?php echo $this->translator('order_tracking_date'); ?></div>
    <div class="grid_3"><?php echo $this->translator('order_tracking_remark'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('order_tracking_cost'); ?></div>
</div>
<div class="grid_12 t_a_bottom" id="ordersDetail">
    <?php foreach ($this->trackings as $row):?>
    <?php
        /**
        * Tracking cost
        **/
        $order_tracking_cost = ($row->order_tracking_cost > 0)?$row->order_tracking_cost:null;

        /**
         * Status
        **/
        $status = isset($this->arrStatus[$row->order_tracking_id])?$this->translator('order_tracking_status_'.$this->arrStatus[$row->order_tracking_id]):'-';
    ?>
    <div class="clearfix t_a_ui_data_list_content">
        <input type="hidden" value="<?php echo $order->order_id;?>" name="order_id"/>
        <input type="hidden" value="<?php echo $row->order_tracking_id;?>" name="order_tracking_id"/>

        <div class="grid_4 alpha"><?php echo $status;?></div>
        <div class="grid_3">
            <span id="t_order_tracking_date_<?php echo $row->order_tracking_id;?>">
                <?php echo ($row->order_tracking_date)?date('d-m-Y',strtotime($row->order_tracking_date)):'-';?>
            </span>
            <span id="in_order_tracking_date_<?php echo $row->order_tracking_id;?>" style="display:none">
                <input value="<?php echo date('Y-m-d',strtotime($row->order_tracking_date));?>" readonly="readonly" type="text" name="order_tracking_date" id="order_tracking_date_<?php echo $row->order_tracking_id;?>" style="width: 70px" class="t_a_new_title" /> <img src="<?php echo $this->APP_STATIC_SERVER; ?>/skins/<?php echo $this->APP_TEMPLATE; ?>/<?php echo $this->APP_SKIN; ?>/images/calendar-select.png" width="16" height="16" onclick="displayCalendar(document.getElementById('order_tracking_date_<?php echo $row->order_tracking_id;?>'),'yyyy-mm-dd',this)"/>
            </span>
        </div>
        <div class="grid_3">
            <span id="t_order_tracking_remark_<?php echo $row->order_tracking_id;?>">
                <?php echo trim($row->order_tracking_remark)?$row->order_tracking_remark:'-'?>
            </span>
            <span id="in_order_tracking_remark_<?php echo $row->order_tracking_id;?>" style="display:none">
                <input type="text" value="<?php echo trim($row->order_tracking_remark);?>" name="order_tracking_remark"/>
            </span>
        </div>
        <div class="grid_2 omega">
            <span id="t_order_tracking_cost_<?php echo $row->order_tracking_id;?>">
                <?php echo ($order_tracking_cost)?$order_tracking_cost:'-';?>
            </span>
            <span id="in_order_tracking_cost_<?php echo $row->order_tracking_id;?>" style="display:none">
                <input type="text" value="<?php echo $order_tracking_cost?>" name="order_tracking_cost" style="width:80px" class="number"/>
            </span>
        </div>
    </div>
    <?php endforeach;?>
</div>
<?php endif;?>

<script type="text/javascript">
$(document).ready(function() {
    /**
    * Create datepicker instances
    */
    $('#order_tracking_date').datepicker({ dateFormat: 'dd/mm/yy' });

    $('#editTrackingForm').validate({
        messages:{
            order_tracking_cost:"<?php echo $this->translator('tracking_cost_invalid_number');?>"
        }
    });
})
</script>
